package com.ams.util;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class TimeFormat {

	public static Timestamp translateStringToTimestamp(String time, String style) {
		SimpleDateFormat format = new SimpleDateFormat(style);
		Timestamp stamp = null;
		try {
			Date date = format.parse(time);
			stamp = new Timestamp(date.getTime());
		} catch (Exception e) {
			//e.printStackTrace();
		}
		return stamp;
	}

	public static Timestamp obtainCurrentTime() {
		return new Timestamp(Calendar.getInstance().getTime().getTime());
	}

	public static String translateTimestampToString(Timestamp stamp,String style) {
		String result = "";
		if (stamp == null) {
			return "";
		}
		SimpleDateFormat format = new SimpleDateFormat(style);
		Calendar cal = Calendar.getInstance();
		cal.setTimeInMillis(stamp.getTime());
		result = format.format(cal.getTime());
		return result;
	}
}
